package com.ssm.changeunit;

import com.ssm.changeunit.persistance.PersistanceException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import com.ssm.changeunit.persistance.TagDAO;
import com.ssm.changeunit.persistance.TagDTO;

/**
 * Tag를 생성하는 Factory
 * 
 * @author 시리우스
 */
public class TagFactory extends AbstractFactory {
    @Override
    public Tag createProduct(String tagName) throws CreateException {
        try {
            TagDAO tagDAO = new TagDAO();
            
            TagDTO tagDTO = tagDAO.find(tagName);
            
            if(tagDTO == null) {
                tagDTO = new TagDTO();
                
                tagDTO.setTagName(tagName);
                
                tagDAO.insert(tagDTO);
            }
            
            return new Tag(tagName);
        }
        catch(PersistanceException ex) {
            throw new CreateException("Tag를 생성하는데 실패했습니다.", ex);
        }
    }
}
